package com.yimiyisu.contract_cust.event.contract;

import com.google.common.eventbus.Subscribe;
import com.yimiyisu.contract_cust.event.model.ContractExportEventModel;
import com.yimiyisu.contract_cust.service.contract.ContractExportService;
import com.zen.ZenData;
import com.zen.ZenEngine;
import com.zen.annotation.Inject;
import com.zen.interfaces.IEvent;

public class ContractExportEvent implements IEvent<ContractExportEventModel> {
    @Inject
    private ZenEngine zenEngine;
    @Inject
    private ContractExportService contractExportService;


    @Override
    @Subscribe
    public void execute(ContractExportEventModel contractExportEventModel) {
        String cdnPath = contractExportService.export(contractExportEventModel);
        String exportTaskId = contractExportEventModel.getTaskId(); // 导出任务id
        String title = contractExportEventModel.getTitle();
        System.out.println("cdnPath:" + cdnPath);
        if (!cdnPath.isEmpty()) {
            // 回填path并修改状态为成功
            zenEngine.execute("patch/export_task", ZenData.create().put("id", exportTaskId).put("status", 6).put("path", cdnPath).put("title", title));
        } else {
            // 更新状态为：导出失败
            zenEngine.execute("patch/export_task", ZenData.create().put("id", exportTaskId).put("status", 11).put("title", title));
        }
    }
}
